<template>
  <view>
    <view class="search-box">
      <my-search @click="gotoSearch"></my-search>
    </view>
    
    <!-- 轮播图区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
          <image :src="item.image_src"/>
        </navigator>
      </swiper-item>
    </swiper>
    
    <!-- 导航区 -->
    <view class="navList">
      <view class="navList-item" v-for="(item,i) in navList" :key="i" @click="navClickHandler(item)">
        <image :src="item.image_src"/>
      </view>
    </view>
    
    <!-- 楼层区 -->
    <view class="floor-container">
      <view class="floor-list" v-for="(item,i) in floorList" :key="i">
        <view class="floor-title">
          <image :src="item.floor_title.image_src"></image>
        </view>
        <view class="floor-product" >
          <navigator class="floor-product-left" :url="item.product_list[0].url">
            <image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}"></image>
          </navigator>
         <view class="floor-product-right">
           <navigator class="product-item" v-for="(proList,p) in item.product_list" :key="p" v-show="p!==0" :url="proList.url">
             <image :src="proList.image_src" mode="widthFix" :style="{width:proList.image_width+'rpx'}"></image>
           </navigator>
         </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        swiperList:[],
        navList:[],
        floorList:[]
      }
    },
  onLoad () {
    console.log('this',this)
    this.getSwiperList()
    this.getNavList()
    this.getFloorList()
  },
  methods: {
    async getSwiperList() {
      const {data:res} = await uni.$http.get ('/api/public/v1/home/swiperdata')
      console.log('轮播图',res)
      if(res?.meta?.status !==200){
        return uni.$showMsg()
      }else {
        this.swiperList = res.message
      }
    },
    async getNavList () {
          const {data:res} =await uni.$http.get('/api/public/v1/home/catitems')
          console.log('分类',res)
          if(res.meta.status !==200) {
            return uni.$showMsg()
          }
          this.navList = res.message
        },
        navClickHandler (item) {
            console.log(item)
            if(item.name =='分类'){
                  uni.switchTab({
                    url:'/pages/cate/cate'
                  })
            }
        },
      async getFloorList() {
         const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
         console.log('楼层',res)
         if(res.meta.status !==200) {
           return uni.$showMsg()
         }
         res.message.forEach(item=>{
           item.product_list.forEach(prod=>{
             prod.url='/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
           })
         })
          this.floorList = res.message
       },
       gotoSearch () {
         uni.navigateTo({
           url:'/subpkg/search/search'
         })
       }
    }}
   
</script>

<style lang="scss">
.search-box {
  position: sticky;
  top: 0;
  z-index: 99;
}
swiper {
  height: 330rpx;
  
  .swiper-item, image {
     width: 100%;
     height: 100%;
   }
}

.navList {
  display: flex;
  justify-content: space-around;
  padding: 15rpx 0;
  margin-bottom: 15rpx;
  .navList-item{
    width: 128rpx;
    height: 140rpx;
    
    image {
      width: 100%;
      height: 100%;
    }
  }
}

.floor-container {
  display: flex;
  flex-direction: column;
  
  .floor-title {
    height: 60rpx;
    image {
      width: 100%;
      height: 100%;
    }
    padding: 10rpx 0;
  }
  
  .floor-product {
    display: flex;
    padding-left: 10rpx;
    .floor-product-left {
      height: 100%;
    }
    .floor-product-right {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
    }
  }
}
</style>
